package cloud.tianai.ram.policy.core.condition.impl;

import cloud.tianai.ram.policy.core.action.Action;
import cloud.tianai.ram.policy.core.condition.Condition;
import cloud.tianai.ram.policy.core.condition.ConditionHandler;
import cloud.tianai.ram.policy.core.condition.ConditionHandlerManager;

/**
 * @Author: 天爱有情
 * @date 2022/3/24 14:21
 * @Description 条件组合器  或者
 */
public class OrConditionHandler implements ConditionHandler {
    @Override
    public boolean match(Condition condition, ConditionHandlerManager conditionHandlerManager, Action action) {
        for (Condition child : condition.getChildren()) {
            if (conditionHandlerManager.match(child, action).isAllow()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String getType() {
        return "or";
    }

    @Override
    public String getDescription() {
        return "或者";
    }
}
